package com.itheima.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletDemo5")
public class ServletDemo5 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 默认会话级别
        Cookie ck1 = new Cookie("abc", "a");
        Cookie ck2 = new Cookie("xyz", "x");

        // 持久化保存2天（以秒为单位）
        ck2.setMaxAge(2 * 24 * 60 * 60);

        response.addCookie(ck1);
        response.addCookie(ck2);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
